package edu.uis.project.frankszoo.model.game;

import java.util.List;

import edu.uis.project.frankszoo.model.card.Card;
import edu.uis.project.frankszoo.model.deck.PlayerDeck;

/**
 * This class represents players still actively playing in a Hand in the game
 * 
 */
public class ActivePlayer extends GamePlayer {

	protected PlayerDeck playerDeck; // The game deck of the player

	/**
	 * This is the constructor for the ActivePlayer. It triggers building of stat map for the playerDeck
	 * 
	 * @param playerName
	 *            Name of the Player
	 * @param playerID
	 *            ID of the Player
	 * @param playerDeck
	 *            The game deck of the player
	 */
	public ActivePlayer(String playerName, String playerID, PlayerDeck playerDeck) {
		super(playerName, playerID, true);
		this.playerDeck = playerDeck;
		playerDeck.buildStatMap();
	}

	/**
	 * Returns the players game Deck
	 * 
	 * @return playerDeck The game deck of the player
	 */
	public PlayerDeck getPlayerDeck() {
		return playerDeck;
	}

	/**
	 * This is the entry point for the AI method which picks the list of cards to be played in a round.
	 * 
	 * @param isFirst
	 *            Indicates whether the player starts the round
	 * @param activeCardSet
	 *            List of cards in the activeCardSet
	 * @return List<Card> List of cards played by the player
	 */
	public List<Card> playCard(boolean isFirst, List<Card> activeCardSet) {

		List<Card> cardsPlayed = null;

		if (isFirst) {
			cardsPlayed = playerDeck.findOptimalFirstPlay();
		} else {
			cardsPlayed = playerDeck.findOptimalSubsequentPlay(activeCardSet);
		}
		if (cardsPlayed != null) {
			playerDeck.removeFromDeckInHand(cardsPlayed);
		}
		return cardsPlayed;
	}

	/* (non-Javadoc)
	 * @see edu.uis.project.frankszoo.model.game.GamePlayer#toString()
	 */
	public String toString() {
		return playerName + ": " + playerDeck;
	}
}
